/*
 * @Author: Ma Xiaohan
 * @Date: 2018-08-19 12:43:12
 * @Last Modified by: Xiaohan Ma
 * @Last Modified time: 2018-08-31 18:05:57
 */
const BasicModel = require('./BasicModel');

module.exports = class extends BasicModel {
  async addAction(params) {
    const id = think.uuid('v4');
    params.data.id = id;
    params.data.status = 0;
    const data = await this.thenAdd(params.data, {relation_id: params.data.relation_id});
    if (data.type === 'add') {
      return {...data, id};
    }
    return {...data};
  }
  async editAction(params) {
    const result = this.where({relation_id: params.data.relation_id}).update(params.data);
    return result;
  }
  async getAction(params) {
    const data = await this.model(params.model).where({id: params.id}).find();
    // blob数据转string返回前端
    let richtext = data.richtext || '';
    richtext = richtext.toString('utf-8');
    data.richtext = richtext;
    return data;
  }
};
